
package com.tenentia.pcmps.swm.business.implementation;

import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;

import com.tenentia.pcmps.swm.Constants;
import com.tenentia.pcmps.swm.business.BusinessLogicException;
import com.tenentia.pcmps.swm.business.interfaces.MarketingPromotionsManager;
import com.tenentia.pcmps.swm.data.DataAccessObjectsFactory;
import com.tenentia.pcmps.swm.data.beans.InsurancePolicyMarketingPromotion;
import com.tenentia.pcmps.swm.data.interfaces.MarketingPromotionsDAO;

/**
 * 
 * @author tEnEntia, S.L.N.E.
 * 
 */
public class MarketingPromotionsManagerImpl implements MarketingPromotionsManager {

	private static final Logger LOGGER = Logger.getLogger(InsurancePoliciesManagerImpl.class.getPackage().getName());

	MarketingPromotionsManagerImpl() {

		super();
	}

	@Override
	public void delete(InsurancePolicyMarketingPromotion promotion) throws BusinessLogicException {

		// TODO Auto-generated method stub

	}

	@Override
	public InsurancePolicyMarketingPromotion get(InsurancePolicyMarketingPromotion promotion) throws BusinessLogicException {

		LOGGER.debug(Constants.STRING_L4J_METHOD_BEGIN);

		try {
			MarketingPromotionsDAO dataAccessObject = (MarketingPromotionsDAO) DataAccessObjectsFactory.getInstance().createNewDataAccessObject(DataAccessObjectsFactory.MARKETING_PROMOTIONS_DAO);
			return dataAccessObject.get(promotion);
		} catch (Exception e) {
			LOGGER.error(e, e);
			throw new BusinessLogicException(e);
		}
	}

	@Override
	public List<InsurancePolicyMarketingPromotion> getAvailableMarketingPromotions(Date date) throws BusinessLogicException {

		LOGGER.debug(Constants.STRING_L4J_METHOD_BEGIN);

		try {
			MarketingPromotionsDAO dataAccessObject = (MarketingPromotionsDAO) DataAccessObjectsFactory.getInstance().createNewDataAccessObject(DataAccessObjectsFactory.MARKETING_PROMOTIONS_DAO);
			return dataAccessObject.getAvailableMarketingPromotions(date);
		} catch (Exception e) {
			LOGGER.error(e, e);
			throw new BusinessLogicException(e);
		}
	}
	
	@Override
	public List<InsurancePolicyMarketingPromotion> getTableItemsByRange(Object filterParameters, Object sortParameters, Integer firstRow, Integer numberOfRows) throws BusinessLogicException {
		
		LOGGER.debug(Constants.STRING_L4J_METHOD_BEGIN);

		try {
			MarketingPromotionsDAO dataAccessObject = (MarketingPromotionsDAO) DataAccessObjectsFactory.getInstance().createNewDataAccessObject(DataAccessObjectsFactory.MARKETING_PROMOTIONS_DAO);
			return dataAccessObject.getTableItemsByRange(filterParameters, sortParameters, firstRow, numberOfRows);
		} catch (Exception e) {
			LOGGER.error(e, e);
			throw new BusinessLogicException(e);
		}
	}
	
	@Override
	public Integer getTableRowCount(Object filterParameters) throws BusinessLogicException {
		
		LOGGER.debug(Constants.STRING_L4J_METHOD_BEGIN);

		try {
			MarketingPromotionsDAO dataAccessObject = (MarketingPromotionsDAO) DataAccessObjectsFactory.getInstance().createNewDataAccessObject(DataAccessObjectsFactory.MARKETING_PROMOTIONS_DAO);
			return dataAccessObject.getTableRowCount(filterParameters);
		} catch (Exception e) {
			LOGGER.error(e, e);
			throw new BusinessLogicException(e);
		}
	}

	@Override
	public InsurancePolicyMarketingPromotion save(InsurancePolicyMarketingPromotion promotion) throws BusinessLogicException {

		LOGGER.debug(Constants.STRING_L4J_METHOD_BEGIN);

		try {
			MarketingPromotionsDAO dataAccessObject = (MarketingPromotionsDAO) DataAccessObjectsFactory.getInstance().createNewDataAccessObject(DataAccessObjectsFactory.MARKETING_PROMOTIONS_DAO);
			return dataAccessObject.save(promotion);
		} catch (Exception e) {
			LOGGER.error(e, e);
			throw new BusinessLogicException(e);
		}
	}

	@Override
	public InsurancePolicyMarketingPromotion update(InsurancePolicyMarketingPromotion promotion) throws BusinessLogicException {

		LOGGER.debug(Constants.STRING_L4J_METHOD_BEGIN);

		try {
			MarketingPromotionsDAO dataAccessObject = (MarketingPromotionsDAO) DataAccessObjectsFactory.getInstance().createNewDataAccessObject(DataAccessObjectsFactory.MARKETING_PROMOTIONS_DAO);
			return dataAccessObject.update(promotion);
		} catch (Exception e) {
			LOGGER.error(e, e);
			throw new BusinessLogicException(e);
		}
	}

}
